//
//  WHFishSpotDetailHV.m
//  WHEasyBizLink
//
//  Created by ShengMeng on 9/25/25.
//

#import "WHFishSpotDetailHV.h"
#import "WHFishSpotModel.h"
#import "UIView+Rounded.h"
#import "SDAutoLayout.h"
#import "myUILabel.h"

@interface WHFishSpotDetailHV ()

/** 图片  **/
@property(nonatomic,strong)UIImageView*micon;

@property (nonatomic, weak)UIButton* introduceBtn;

/** 名称  **/
@property (nonatomic, weak)UILabel *nameLabel;

@property (nonatomic, weak)UIScrollView *scrollView;

/** 关注  **/
@property (nonatomic, weak)UIButton *attentionBtn;
/** 地址  **/

@property (nonatomic, weak)UIImageView *addressImage;
@property (nonatomic, weak)UIButton* addressBtn;
@property (nonatomic, weak)UILabel *mAppTimeTitle;

@property(nonatomic,strong)UIView*mbgView;


@property (nonatomic, strong)NSMutableArray *payWays;

@property (nonatomic,strong)WHFishSpotModel *model;


@end

@implementation WHFishSpotDetailHV


-(instancetype)initWithFrame:(CGRect)frame withModel:(WHFishSpotModel *)model
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.payWays        = [NSMutableArray new];
        //1.创建控件
        [self createUIControls];
        //2.设置样式(布局)
        [self setUpUIControlsLayout];
        self.model = model;
        self.backgroundColor= [UIColor clearColor];
    }
    return self;
}

-(void)createUIControls
{
    self.backgroundColor = [UIColor clearColor];
    _mbgView = [[UIView alloc] init];
    _mbgView.backgroundColor = [UIColor whiteColor];
    self.mbgView.userInteractionEnabled = YES;
    [self addSubview:self.mbgView];
    _micon = [[UIImageView alloc] init];
    
    [self.mbgView addSubview:self.micon];
    
    UIButton* introduceBtn= [[UIButton alloc]init];
    introduceBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [introduceBtn setTitle:@"钓场介绍>" forState:UIControlStateNormal];
    introduceBtn.tag = 1;
    [introduceBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.mbgView addSubview:introduceBtn];
    [introduceBtn addTarget:self action:@selector(selecetBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    introduceBtn.backgroundColor = [UIColor colorWithHexString:@"#767676" alpha:0.1];
    _introduceBtn = introduceBtn;
    introduceBtn.layer.cornerRadius = 5;
    
    /**  应用名称  **/
    myUILabel*nameLabel = [[myUILabel alloc]init];
    nameLabel.font = [UIFont systemFontOfSize:18];
    //appNameLabel.textColor = [UIColor whiteColor];
    nameLabel.textColor = [UIColor colorWithHexString:@"#3C3C3C" alpha:1.0];
    nameLabel.numberOfLines = 2;
    [self.mbgView addSubview:nameLabel];
    nameLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
    _nameLabel = nameLabel;
    
    UIButton*attentionBtn = [[UIButton alloc]init];
    [attentionBtn setImage:[UIImage imageNamed:@"shoucang"] forState:UIControlStateNormal];
    [attentionBtn setImage:[UIImage imageNamed:@"Filled_Star"] forState:UIControlStateSelected];
    
    self.attentionBtn = attentionBtn;
    attentionBtn.tag = 2;
    [self.mbgView addSubview:attentionBtn];
    [attentionBtn addTarget:self action:@selector(selecetBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIScrollView *scrollView = [[UIScrollView alloc]init];
    //scrollView.pagingEnabled = YES;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.bounces = NO;
    [self.mbgView addSubview:scrollView];
    _scrollView  = scrollView;
    
    UIImageView*addressImage = [[UIImageView alloc]init];
    addressImage = [[UIImageView alloc] init];
    addressImage.image = [UIImage imageNamed:@"dizhi"];
    self.addressImage = addressImage;
    [self.mbgView addSubview:addressImage];
    
    UIButton* addressBtn= [[UIButton alloc]init];
    [addressBtn setTitleColor:[UIColor colorWithHexString:@"#767676" alpha:1.0] forState:UIControlStateNormal];
    addressBtn.titleLabel.font = [UIFont systemFontOfSize:14];
//    [moreButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.mbgView addSubview:addressBtn];
    _addressBtn = addressBtn;
    
    UILabel*appTimeTitle = [[UILabel alloc]init];
    appTimeTitle.font = [UIFont systemFontOfSize:14];
    appTimeTitle.textColor = [UIColor colorWithHexString:@"#767676" alpha:1.0];
    [self.mbgView addSubview:appTimeTitle];
    appTimeTitle.numberOfLines = 1;
    appTimeTitle.backgroundColor = [UIColor colorWithHexString:@"#767676" alpha:0.1];
    _mAppTimeTitle = appTimeTitle;
    appTimeTitle.layer.cornerRadius = 5;
    
}

- (void)setUpUIControlsLayout
{
    _mbgView
    .sd_layout
    .topSpaceToView(self, 5)
    .bottomSpaceToView(self,10)
    .leftSpaceToView(self, 20)
    .rightSpaceToView(self,20);
    
    _micon
    .sd_layout
    .topSpaceToView(self.mbgView,0)
    .leftSpaceToView(self.mbgView,0)
    .rightSpaceToView(self.mbgView,0)
    .heightIs(160);
    
    /**  应用名称  **/
    _nameLabel
    .sd_layout
    .topSpaceToView(self.micon,10)
    .leftSpaceToView(self.mbgView,10)
    .widthIs(ScreenW*2/3)
    .heightIs(30);
    
    _attentionBtn.sd_layout
    .centerYEqualToView(_nameLabel)
    .rightSpaceToView(self.mbgView,10)
    .widthIs(25)
    .heightIs(25);
    
    _scrollView.sd_layout
    .topSpaceToView(self.nameLabel,5)
    .leftSpaceToView(self.mbgView,10)
    .rightSpaceToView(self.mbgView,10)
    .heightIs(20);
   
    _addressImage
    .sd_layout
    .topSpaceToView(self.nameLabel,30)
    .leftSpaceToView(self.mbgView,10)
    .widthIs(20)
    .heightIs(20);
    
    _addressBtn
    .sd_layout
    .topSpaceToView(self.nameLabel,30)
    .leftSpaceToView(self.addressImage,0)
    .rightSpaceToView(self.mbgView,40)
    .heightIs(20);
    
    _mAppTimeTitle
    .sd_layout
    .topSpaceToView(self.addressImage,10)
    .leftSpaceToView(self.mbgView,10)
    .widthIs(120)
    .heightIs(20);
    
    _introduceBtn
    .sd_layout
    .centerYEqualToView(_micon)
    .rightSpaceToView(self.mbgView,10)
    .widthIs(80)
    .heightIs(30);
    
    

}

-(void)setModel:(WHFishSpotModel *)model
{
    _model = model;
    _micon.image = [UIImage imageNamed:_model.image];
    _nameLabel.text = _model.name;
    
    //_personTitle.text = _model.address;
    [_addressBtn setTitle:_model.address forState:UIControlStateNormal];
    _mAppTimeTitle.text =_model.time;
   
    
    for(int i=0;i<self.payWays.count;i++)
    {
        UILabel*stateTitle  = self.payWays[i];
        [stateTitle removeFromSuperview];
    }
    
    [self.payWays removeAllObjects];
    for(int i=0;i<_model.playWays.count;i++)
    {
        NSString*payWay = _model.playWays[i];
        
        UILabel*stateTitle  = [[UILabel alloc]init];
        stateTitle .font = [UIFont systemFontOfSize:14];
        stateTitle.layer.borderWidth = 0.5;
        stateTitle.layer.borderColor =  [UIColor colorWithHexString:@"#767676" alpha:1.0].CGColor;
        stateTitle.textColor = [UIColor colorWithHexString:@"#767676" alpha:1.0];
        [self.scrollView addSubview:stateTitle];
        stateTitle .numberOfLines = 1;
        stateTitle.textAlignment = NSTextAlignmentCenter;
        stateTitle.text = payWay;
        stateTitle
        .sd_layout
        .topSpaceToView(self.scrollView,0)
        .leftSpaceToView(i== 0?self.scrollView:self.payWays[i-1],i== 0?0:10)
        .widthIs(60)
        .heightIs(20);
        [self.payWays addObject:stateTitle];
    }
    
    self.scrollView.contentSize =CGSizeMake(model.playWays.count*70,20);

}

-(void)selecetBtnClick:(UIButton*)btn
{
    if (btn.tag==2) {
        
        if (btn.isSelected) {
            btn.selected =NO;
        }else
        {
            btn.selected = YES;
        }
    }
    if ([_delegate respondsToSelector:@selector(wHFishSpotDetailHVBtnClick:)]) {
        [_delegate wHFishSpotDetailHVBtnClick:btn];
    }

}

@end

